
<html>

<head>
    <include file="public@head" title="栏目管理" keywords="后台管理系统" />
</head>

<body class="layui-layout-admin">
    <include file="public@header" />
    <include file="public@side" />
    <div class="layui-body">
        <div class="layui-breadcrumb" lay-filter="breadcrumb">
            <a href="{:url('tdadmin/index/index')}">主页</a>
            <a>内容管理</a>
            <a href="#"><cite>专业管理</cite></a>
        </div>
        <div class="layui-fluid">
            <div class="layui-card">
                <div class="layui-card-header">
                    专业管理
                    <div class="layui-btn-group fr">
                        <a class="layui-btn layui-btn-sm layui-btn-normal" href="{:url('add')}?college_id={$college_id}">添加专业</a>
                    </div>
                </div>
                <div class="layui-card-body">
                    <table class="layui-hide" id="categorys" lay-filter="categorys"></table>
                    <script type="text/html" id="statusTpl">
                    <input type="checkbox" lay-skin="switch" {{ d.status==1 ? 'checked' : '' }} lay-filter="switch" data-url="{:url('doSwitch')}?id={{d.id}}&field=status" lay-text="显示|隐藏">
                </script>
                    <script type="text/html" id="barTpl">
                    <a class="layui-btn layui-btn-sm layui-btn-warm" lay-event="edit">编辑</a>
                    <a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="del">删除</a>
                </script>
                </div>
            </div>
        </div>
    </div>
    <include file="public@scripts" />
    <script>
        var table = layui.table;

        table.render({
            elem: '#categorys',
            url: "{:url('specialty/apiGetSpecialty')}?college_id={$college_id}",
            cols: [
                [
                    { field: 'id', width: 60, title: 'ID', align: 'center' },
                    { field: 'college_name', title: '学院名称', width: 200, edit: 'text', align: 'center' },
                    { field: 'specialty_name', title: '专业名称', width: 200, edit: 'text', align: 'center' },
                    { field: 'sort', title: '排序', width: 120, edit: 'text', align: 'center' },
                    { field: 'status', title: '状态', width: 120, templet: '#statusTpl', unresize: true, align: 'center' },
                    { title: '操作', toolbar: '#barTpl', align: 'center' }
                ]
            ]
        });

        table.on('edit(categorys)', function (obj) {
            $.ajax({
                type: "post",
                url: "{:url('updateField')}?id=" + obj.data.id + "&field=" + obj.field + "&value=" + obj.value,
                async: true
            });
        });

        //监听工具条
        table.on('tool(categorys)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;
            if (layEvent === 'edit') {
                window.location.href = "{:url('edit')}?id=" + data.id;
            } else if (layEvent === 'del') {
                layer.confirm('您将删除【' + data.specialty_name + '】', function (index) {
                    window.location.reload();
                    layer.close(index);
                    $.ajax({
                        type: "post",
                        url: "{:url('delete')}?id=" + data.id,
                        async: true
                    });
                });
            }
        });

                table.on('edit(lists)', function (obj) {
                        var value = obj.value,
                            data = obj.data,
                            field = obj.field;
                        $.ajax({
                            type: "post",
                            url: "{:url('updateField')}?id=" + data.id + "&field=" + field + "&value=" + value,
                        });
                    });
    </script>
</body>

</html>